package com.kreedx.kdemo.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.kreedx.kdemo.R;
import com.tmall.wireless.tangram.structure.BaseCell;
import com.tmall.wireless.tangram.structure.view.ITangramViewLifeCycle;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DebugView extends FrameLayout implements ITangramViewLifeCycle {


    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.image)
    ImageView image;

    public DebugView(@NonNull Context context) {
        super(context);
        init();
    }

    public DebugView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DebugView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        View view = inflate(getContext(), R.layout.view_debug, this);
        ButterKnife.bind(this,view);

    }

    @Override
    public void cellInited(BaseCell cell) {

    }

    @Override
    public void postBindView(BaseCell cell) {
        String imgUrl = cell.optStringParam("imgUrl");
        String titleText = cell.optStringParam("title");

        title.setText(titleText);
        Glide.with(getContext()).load(imgUrl).into(image);

    }

    @Override
    public void postUnBindView(BaseCell cell) {

    }
}
